﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace SpriteBuilder
{
    class Camera2D
    {
        protected float x;
        protected float y;
        public Vector2 Position { get { return new Vector2(x, y); } set { x = value.X; y = value.Y; } }
        protected float rotation;
        public float Rotation { get { return rotation; } set { rotation = value; } }
        protected float zoom;
        public float Zoom { get { return zoom; } set { zoom = MathHelper.Clamp(value,0.1f,50); } }
        protected Matrix transform;
        public Matrix Transform { get { return transform; }}

        public Camera2D(GraphicsDevice device)
        {
            Position = new Vector2(0, 0);
            Rotation = 0.0f;
            Zoom = 1.0f;
            //transform = Matrix.CreateTranslation(new Vector3(-Position.X, -Position.Y, 0)) *
            //                             Matrix.CreateRotationZ(Rotation) *
            //                             Matrix.CreateScale(new Vector3(Zoom, Zoom, 1)) *
            //                             Matrix.CreateTranslation(new Vector3(device.Viewport.Width * 0.5f, device.Viewport.Height * 0.5f, 0));
 
        }

        public Matrix getTransform(GraphicsDevice device)
        {
            transform = Matrix.CreateTranslation(new Vector3(-Position.X, -Position.Y, 0)) *
                                         Matrix.CreateRotationZ(Rotation) *
                                         Matrix.CreateScale(new Vector3(Zoom, Zoom, 1)) *
                                         Matrix.CreateTranslation(new Vector3(device.Viewport.Width * 0.5f, device.Viewport.Height * 0.5f, 0));

            return transform;
        }

    }
}
